extends "../xuefeng-2/xuefeng-2.gd"


func _extInit():
	._extInit()
	lv = 3             #等级的设置
	addSkill("当场上存在其他友军时，将所受炮击/雷击伤害由1名血量最高的友军和1名随机敌军分摊", "不沉的幸运舰")

func _onHurt(atkInfo):
	._onHurt(atkInfo)
	if atkInfo.atkType == sys.AtkType.GUN or atkInfo.atkType == sys.AtkType.TORPEDO:
		fentan(atkInfo)
	
func fentan(atkInfo):
	if enemy == null || enemy.isDeath:
		reSelect(true)
	if ally == null || ally.isDeath:
		reSelect(false)
	if enemy != null && not enemy.isDeath:
		var dmg = atkInfo.atkVal*0.5
		azurHurtChara(enemy, dmg, atkInfo.hurtType, sys.AtkType.EFF, "不沉的幸运舰")
	
	if ally == null or ally.isDeath or team == 2:
		atkInfo.hurtVal *= 0.5
	else:
		atkInfo.atkCha.azurHurtChara(ally, atkInfo.atkVal*0.6, atkInfo.hurtType, sys.AtkType.EFF, atkInfo.get("skill"))
		atkInfo.hurtVal = 0

func reSelect(isEnemy=false):
	if not isEnemy:
		var allys = getAllChas(2)
		if allys.size() == 0:
			return
		allys.sort_custom(self,"sortXF")
		for i in allys:
			if i.xfSkillFlag and not i.isDeath and not isSumm:
				ally = i
				break
	else:
		var enemys = getAllChas(1)
		if enemys.size() == 0:
			return
		enemys.shuffle()
		for i in enemys:
			if i.xfSkillFlag and not i.isDeath and i.type != sys.CharaClass.BOSS:
				enemy = i
				break

func sortXF(a,b):
	return a.att.maxHp > b.att.maxHp
